package cn.tedu.zhxy.service.impl;


import cn.tedu.zhxy.dto.LoginDTO;
import cn.tedu.zhxy.entity.Admin;
import cn.tedu.zhxy.mapper.AdminMapper;
import cn.tedu.zhxy.service.AdminService;
import cn.tedu.zhxy.util.MD5;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-07-19
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Override
    public Admin login(LoginDTO loginDTO) {
        QueryWrapper<Admin>  queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",loginDTO.getUsername());
        queryWrapper.eq("password", MD5.encrypt(loginDTO.getPassword()));
        Admin admin = baseMapper.selectOne(queryWrapper);
        return admin;

    }

    @Override
    public IPage<Admin> getAllAdmin(Page<Admin> pageParam, String adminName) {
        QueryWrapper  queryWrapper = new QueryWrapper();
        if (!StringUtils.isEmpty(adminName)) {
            queryWrapper.eq("name",adminName);
        }
        Page page = baseMapper.selectPage(pageParam, queryWrapper);
        return page;
    }
}
